package DBModel

import (
	"misc/mgo/bson"
	. "utils"
)

type AccountModel struct {
	_Id      bson.ObjectId `bson:"_id"`
	Account  string
	NickName string
	Pwd      string
}

func NewAccount(account string, nickName string, pwd string) {
	regModel := &AccountModel{_Id: bson.NewObjectId(), Account: account, NickName: nickName, Pwd: pwd}
	err := Db.C("sp_Account").Insert(regModel)
	CheckError(err)
}

func AccountModel_GetByAccount(account string) *AccountModel {
	query := Db.C("sp_Account").Find(bson.M{"account": account})
	retAccount := &AccountModel{}
	err := query.One(retAccount)
	if err == nil {
		return retAccount
	}
	return nil
}
func AccountModel_CheckByAccount(account string) bool {
	num, _ := Db.C("sp_Account").Find(bson.M{"account": account}).Count()
	if num > 0 {
		return true
	}
	return false
}
